#include "LevelUpDialog.h"
#include "../../../model/proxy/UserProxy.h"
#include "../../../model/proxy/ItemProxy.h"

LevelUpDialog::LevelUpDialog(void)
	:mLevel(NULL),mAttack(NULL),mDefense(NULL),mEquipCount(NULL),mFriendCount(NULL),mProficiency(NULL)
{
}

LevelUpDialog::~LevelUpDialog(void)
{
	CC_SAFE_RELEASE(mLevel);
	CC_SAFE_RELEASE(mAttack);
	CC_SAFE_RELEASE(mDefense);
	CC_SAFE_RELEASE(mEquipCount);
	CC_SAFE_RELEASE(mFriendCount);
	CC_SAFE_RELEASE(mProficiency);
}

bool LevelUpDialog::onAssignCCBMemberVariable( CCObject * pTarget, CCString * pMemberVariableName, CCNode * pNode )
{
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mLevel", CCLabelTTF *, this->mLevel);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mAttack", CCLabelTTF *, this->mAttack);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mDefense", CCLabelTTF *, this->mDefense);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mEquipCount", CCLabelTTF *, this->mEquipCount);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mFriendCount", CCLabelTTF *, this->mFriendCount);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mProficiency", CCLabelTTF *, this->mProficiency);
	return false;
}

SEL_MenuHandler LevelUpDialog::onResolveCCBCCMenuItemSelector(CCObject * pTarget, CCString * pSelectorName )
{
	CCB_SELECTORRESOLVER_CCMENUITEM_GLUE(this, "onDoItClick", LevelUpDialog::onDoItClick);
	return NULL;
}

SEL_CCControlHandler LevelUpDialog::onResolveCCBCCControlSelector( CCObject * pTarget, CCString * pSelectorName )
{
	CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onFacebookBtnClick", LevelUpDialog::onFacebookBtnClick);
	CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onCloseBtnClick", LevelUpDialog::onCloseBtnClick);
	return NULL;
}

void LevelUpDialog::onNodeLoaded( CCNode * pNode, CCNodeLoader * pNodeLoader )
{

}

void LevelUpDialog::onEnter()
{
	ModelDialog::onEnter();
	refresh();
}

void LevelUpDialog::onExit()
{
	ModelDialog::onExit();
}

bool LevelUpDialog::init()
{
	return true;
}

void LevelUpDialog::refresh()
{
	UserVO& userVO = UserProxy::getSingletonPtr()->userVO;
	mLevel->setString(fcs("%d", userVO.level));
	mAttack->setString(fcs("%d-%d", userVO.atkMin, userVO.atkMax));
	mDefense->setString(fcs("%d-%d", userVO.defMin, userVO.defMax));
	mEquipCount->setString(fcs("%d", ItemProxy::getSingletonPtr()->getEquipCount()));
	mFriendCount->setString(fcs("%d", 10));
	mProficiency->setString(fcs("%d", userVO.proficiency));
}

void LevelUpDialog::_onNotification( CCObject* object )
{
	
}

void LevelUpDialog::onDoItClick(CCObject* pSender)
{
    
}

void LevelUpDialog::onFacebookBtnClick( CCObject * pSender, CCControlEvent pCCControlEvent )
{
	close();
}

void LevelUpDialog::onCloseBtnClick( CCObject * pSender, CCControlEvent pCCControlEvent )
{
	close();
}
